request = (urlS,callback)=>
    urlObj = url.parse(urlS)
    # console.log urlS,urlObj
    urlObj.port = 80
    urlObj.method = 'GET'
    if !callback
        callbck = ()->
            return
    T.log url.format(urlS)
    try
        req = http.request(urlObj, (res)=> 
            # @emit 'onFetchstart', url.parse(urlS),req
            # console.log("Got response: " + res.statusCode, res.headers)
            if(res.statusCode is (301 or 302))
                u2= res.headers.location
                console.log urlS + ' forword to '+ u2
                # @emit 'onFetchredirect' ,url.parse(urlS),u2,res
                try
                    request u2,callback
                catch e
                    if !retryMap[u2] then retryMap[u2]=0
                    else
                        retryMap[u2]++
                    if(retryMap[u2]<2)
                        request u2,callback
                    else 
                        callback()
            buffers = []
            size = 0
            # console.log c++
            res
            .on('data', (buffer)=> 
                buffers.push(buffer)
                size += buffer.length
            )
            .on('end', ()=> 
                responseBuffer = new Buffer size
                pos = 0;
                try
                    for i in [0..buffers.length-1]
                        buffers[i].copy responseBuffer, pos
                        pos += buffers[i].length
                # T.logEnd urlS
                    callback url.parse(urlS),responseBuffer,res 
                catch e
                    console.log e
                    # errStr = JSON.stringify e
                    # throw new Error()

                # @emit 'onFetchComplete',url.parse(urlS),responseBuffer,res
            )
        )
        req.on('error', (e)=>
            # @emit 'onFetchclienterror',e
            console.log("Got error: " + e.message)
            throw e
            # request urlS,callback
        )
        # req.write('')
        req.end()
    catch e
        errStr = JSON.stringify e
        console.log (errStr)
        if !retryMap[urlS] then retryMap[urlS]=0
        else
            retryMap[urlS]++
        if(retryMap[urlS]<2)
            request urlS,callback
        else 
            fetchEnd()